//
//  YATaskUserGetInfo.m
//  YoucApi
//
//  Created by Liam on 12/8/12.
//
//

#import "YATaskUserGetInfo.h"
#import "YARespUserInfo.h"

@implementation YATaskUserGetInfo

TASK_AUTO_REGISTER(TaskUserGetInfo);

- (NSString *)_getUriParamA
{
	return @"get_user_info";
}

- (BOOL)_checkValidResponse:(id)responseObject
{
	return [responseObject isKindOfClass:[NSDictionary class]];
}

- (void)_dealWithJSONResponse:(id)responseObject withError:(NSError *)error
{
	YARespUserInfo *respUserInfo = [[[YARespUserInfo alloc] initWithError:error context:self.context] autorelease];
	
	YAObjUserInfo * userInfo = [[[YAObjUserInfo alloc] init] autorelease];
	
	userInfo.userId = [self.params objectForKey:KEY_UID];
	
	if ([error code] == YoucApiErrorSuccess)
	{        
		NSDictionary *jsonDict = (NSDictionary *)responseObject;

		userInfo.nickname = SAFE_STRING([jsonDict objectForKey:KEY_NICKNAME]);
		userInfo.sex = SAFE_STRING([jsonDict objectForKey:KEY_SEX]);
		userInfo.sign = SAFE_STRING([jsonDict objectForKey:KEY_SIGN]);
		userInfo.location = SAFE_STRING([jsonDict objectForKey:KEY_LOCATION]);
		userInfo.photo = SAFE_STRING([jsonDict objectForKey:KEY_PHOTO]);
	}
	
	respUserInfo.userInfo = userInfo;

	if ([self.delegate respondsToSelector:@selector(userGetInfoResponse:respUserInfo:)])
	{
		[self.delegate userGetInfoResponse:self respUserInfo:respUserInfo];
	}
}

@end
